package app.caihan.wanandroid.ui.wxarticle

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import app.caihan.scframe.api.retrofit2.checkResult
import app.caihan.scframe.base.viewmodel.BaseViewModel
import app.caihan.scframe.constant.DEBUG_TAG
import app.caihan.wanandroid.model.ScWanAndroidFactory
import app.caihan.wanandroid.model.bean.Chapters
import com.blankj.utilcode.util.LogUtils


class WxArticleFragmentModel : BaseViewModel(){

    private val repository by lazy { ScWanAndroidFactory.makeWanRepository() }

    private val _chapters :MutableLiveData<List<Chapters>> by lazy {  MutableLiveData<List<Chapters>>()}

    val chapters: LiveData<List<Chapters>> = _chapters

    fun getWxArticleChapters(){
        launchUI {
            showLoadingView()
            repository.getWxArticleChapters()
                .checkResult(
                    onSuccess = {
                        _chapters.value = it
                    }, onError = {
                        LogUtils.dTag(DEBUG_TAG, "getWxArticleChapters onError $it")
                    }
                )
            showContentView()
        }
    }
}